#include "gets.h"

int gets(int netfd,char * filename){
    
    train_t train;
    train.length = strlen(filename);
    strcpy(train.data,filename);
    
    send(netfd,&train,sizeof(int)+train.length,MSG_NOSIGNAL);
    
    int fd = open(filename,O_RDWR);
    while(1){
        bzero(&train,sizeof(train));

        ssize_t ret = read(fd,train.data,sizeof(train.data));
        train.length = ret;
        send(netfd,&train,sizeof(int)+train.length,MSG_NOSIGNAL);
        if(ret==0){
            break;
        }
    }
    close(fd);
    return 0;
}
